package com.lsf.modules.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lsf.common.api.vo.Result;
import com.lsf.modules.system.entity.Reply;
import com.lsf.modules.system.service.ReplyService;
import com.lsf.modules.system.service.FollowService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 首页
 *
 * @author Alexander
 */
@RestController
@Slf4j
@RequestMapping("/sys/index")
public class IndexController {

    @Resource
    private ReplyService replyService;

    @Resource
    private FollowService followService;

    @GetMapping("/getArticlesByFollowerId")
    public Result<IPage<Reply>> getArticlesByFollowerId(@RequestParam String followerId,
                                                        @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
                                                        @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize) {
        Result<IPage<Reply>> result = new Result<>();
        Page page = new Page<>(pageNo, pageSize);
        if (StringUtils.isEmpty(followerId)) {
            result.setMessage("关注者不存在!");
            result.setSuccess(false);
            return result;
        }
        IPage<Reply> pageList = followService.selectArticlesByFollowerId(page, followerId);
        result.setResult(pageList);
        result.setSuccess(true);
        return result;
    }
}
